package com.caigou.controller;

import com.caigou.bean.cms.entity.FooterConfig;
import com.caigou.bean.cms.entity.FriendshipLink;
import com.caigou.bean.exam.entity.Users;
import com.caigou.pojo.HeaderConfig;
import com.caigou.security.utils.CurrentUser;
import com.caigou.service.ChannelService;
import com.caigou.service.FooterConfigService;
import com.caigou.service.FriendshipLinkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Slf4j
public class PreviewController {
    @Resource
    private FooterConfigService footerConfigService;

    @Resource
    private FriendshipLinkService friendshipLinkService;

    @Resource
    private ChannelService channelService;


    @RequestMapping("/footer/preview")
    public String preview(ModelMap model, @CurrentUser Users user){
        Map<String, Object> data = new HashMap<>();// 数据字段
        List<FriendshipLink> latestFriendshipLinks = friendshipLinkService.listFriendshipLink();
        HeaderConfig appConfig = channelService.loadChannelHeaderConfig("100011001");// 获取全局配置app下载二维码数据
        data.put("latestFriendshipLinks", latestFriendshipLinks);
        data.put("channelName", appConfig.getChannelName());
        data.put("siteLogo", appConfig.getSiteLogo());
        data.put("channelDescription", appConfig.getChannelDescription());

        //页脚logo图片及文字
        List<FooterConfig> footerTextList = (List<FooterConfig>)footerConfigService.listFooterText().getData();
        FooterConfig footerImage = (FooterConfig)footerConfigService.getFooterImage().getData();
        data.put("footerImage", footerImage);
        data.put("footerTextList", footerTextList);

        //将数据data设置到model中
        model.addAllAttributes(data);

        return "/web/html/footer/footer";
    }


}
